<template>
    <div>
        <div class="e-form">
            <BillTop  @cancel="handleClose"></BillTop>
            <div class="tabs" style="margin-bottom: 120px">
                <div class="tabs-title">基本信息</div>
                <div style="width: 100%" class="form">
                     <el-form
                                :model="basicForm"
                                :label-width="formLabelWidth"
                                ref="ruleForm"
                                :rules="rules"
                                class="demo-ruleForm"
                            >
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="计划编号：">
                                            <span>{{ basicForm.billNo }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="单据机构：">
                                            <span>{{ basicForm.orgName }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="采购方式：">
                                             <span>{{
                                        basicForm.purchaseType == 0
                                            ? '普通采购'
                                            : '集中采购'
                                    }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                <el-form-item label="变更日期："
                                prop="planDate"
                                >
                                    <el-date-picker
                                        value-format="yyyy-MM-dd"
                                        :clearable="false"
                                        type="date"
                                        placeholder="选择日期"
                                        v-model="basicForm.planDate"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                                </el-row>

                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="不含税计划金额（元）："
                                        >
                                            <span>
                                                {{
                                                    basicForm.amountExcludingTax
                                                }}
                                            </span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="原计划金额："
                                            prop="year"
                                        >
                                               <span>
                                        {{ basicForm.amount }}
                                    </span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="税率%："
                                            prop="taxRate"
                                        >
                                            <el-input
                                                @input="onTaxRate"
                                                v-enter-integer2="{
                                            set:this,
                                            val:'basicForm',
                                            key:'taxRate'
                                            }"
                                                v-model="basicForm.taxRate"
                                                autocomplete="off"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="税额："
                                            prop="taxAmount"
                                        >
                                            <el-input
                                                v-enter-float="{
                                                    set: this,
                                                    val: 'basicForm',
                                                    key: 'taxAmount'
                                                }"
                                                v-model="basicForm.taxAmount"
                                                autocomplete="off"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="变更后计划金额（元）：">
                                            <span>
                                                {{ basicForm.amountChanged }}
                                            </span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="填报人：">
                                            <span>{{
                                                basicForm.preparer
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="币种："
                                            prop="currency"
                                        >
                                     <span>{{ basicForm.currency }}</span>

                                        </el-form-item>
                                    </el-col>

                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="变更后期数：">
                                            <span>{{ basicForm.period }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12"> </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="备注：">
                                            <el-input
                                                type="textarea"
                                                v-model="basicForm.remarks"
                                                autocomplete="off"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="本位币：">
                                            <span>{{
                                                basicForm.baseCurName
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item
                                            label="调拨金额(本位币)："
                                        >
                                            <span>{{
                                                basicForm.transportationCost
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="人民币汇率：">
                                            <span>{{ basicForm.rmbRate }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12"> </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="本位币汇率：">
                                            <span>{{
                                                basicForm.baseCurRate
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12"> </el-col>
                                </el-row>
                            </el-form>
                </div>
            </div>
            <div class="buttons">

                <el-button
                    type="primary"
                    size="small"
                    style="background: #2e61d7"
                    @click="addSave"
                    >保存</el-button
                >
                <el-button size="small" @click="handleClose">关闭</el-button>
            </div>
        </div>
    </div>
</template>

<script>

import planRequest from '@/api/turnover/plan.js'

export default {
    data () {
        return {
            //基础信息
            basicForm: {
               	'amount': 0,
                'amountChanged': 0,
                'amountExcludingTax': 0,
                'annualDemandPlanBillId': '',
                'annualDemandPlanBillNo': '',
                'billId': '',
                'billNo': '',
                'currency': '',
                'currencyId': '',
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'period': 0,
                'planDate': '',
                'preparer': '',
                'preparerId': '',
                'purchaseType': 0,
                'remarks': '',
                'rmbRate': 0,
                'state': '',
                'taxAmount': 0,
                'taxRate': 0,
                'workId': '',
                'year': ''
            },
            rules: {

                taxRate: [
                    { required: true, message: '请填写税率', trigger: 'blur' }
                ],
                taxAmount: [
                    { required: true, message: '请填写税额', trigger: 'blur' }
                ]
            },
            formLabelWidth: '180px',
            currencyArr: [], //币种列表

            stateArr: ['草稿', '审核中', '已审核', '已作废'],

        }
    },
    created () {
        this.id = this.$route.query.billid
        this.basicForm.annualDemandPlanBillId = this.id
        this.getBasicInfo()

        this.getUserInfo()
    },
    components: {
        // SelectAddr
    },
    computed: {},
    methods: {
        //获取本地登录信息
        getUserInfo () {
            const userInfo = JSON.parse(window.localStorage.getItem('vuex')).userInfo.orgInfo
            this.basicForm.orgId = userInfo.orgId
            this.basicForm.orgName = userInfo.orgName
        },
        getBasicInfo () {
            planRequest.turnoverAnnualDemandPlanChangedInitData(this.id)
                .then(res => {
                    res.amountExcludingTax = null
                    for (let key in res) {
                        this.basicForm[key] = res[key]
                    }
                })
        },
        //税率失去焦点的时候 计算 税额 = 不含税计划金额（元）*税率%
        onTaxRate () {
            if (
                this.basicForm.amountExcludingTax != 0 &&
        this.basicForm.taxRate != 0
            ) {
            // 税额
                this.basicForm.taxAmount =
          Number((this.basicForm.amountExcludingTax * this.basicForm.taxRate) / 100).toFixed(2)
            }
        },
        //获取币种列表
        getCurrency () {
            this.$Ajax
                .httpGet({
                    url: '/config/kv/getDicValue',
                    params: {
                        dicName: '币种',
                        dicKey: ''
                    },
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                }).then(res=>{
                    this.currencyArr = res
                })
        },
        //选择币种的事件
        changeCurrency () {
            const obj = this.currencyArr.find(item=>item.kvKey === this.basicForm.currency)
            this.basicForm.currencyId = obj.kvId
        },
        //获取当前日期
        //基本信息保存
        addSave () {
            this.$Ajax
                .httpPost({
                    url: '/turnover/annualDemandPlanChanged/create',
                    params: this.basicForm
                })
                .then(res => {
                    this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                        this.$router.push({
                            path: '/yearPlanChengeEdit',
                            query: {
                                billid: res,
                                name: 'detailed'
                            }
                        })
                    },
                    null,
                    this.handleClose
                    )
                })
        },
        //取消
        handleClose () {
            this.$router.replace('/yearNeedPlan')

        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
.e-table {
    min-height: auto;
    background: #fff;
}
.separ {
    width: 30px;
    height: 40px;
    line-height: 18px;
    text-align: center;
}
.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

::v-deep.el-input--suffix .el-input__inner {
    padding-right: 5px;
}
::v-deep.el-table .cell {
    text-align: center;
}
</style>
